package com.itheima.service.impl;

import com.itheima.dao.SysOperLogDao;
import com.itheima.pojo.SysOperLog;
import com.itheima.service.SysOperLogService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (SysOperLog)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:52
 */
@Service("sysOperLogService")
public class SysOperLogServiceImpl implements SysOperLogService {
    @Resource
    private SysOperLogDao sysOperLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param operId 主键
     * @return 实例对象
     */
    @Override
    public SysOperLog queryById(Long operId) {
        return this.sysOperLogDao.queryById(operId);
    }

    /**
     * 分页查询
     *
     * @param sysOperLog 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SysOperLog> queryByPage(SysOperLog sysOperLog, PageRequest pageRequest) {
        long total = this.sysOperLogDao.count(sysOperLog);
        return new PageImpl<>(this.sysOperLogDao.queryAllByLimit(sysOperLog, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param sysOperLog 实例对象
     * @return 实例对象
     */
    @Override
    public SysOperLog insert(SysOperLog sysOperLog) {
        this.sysOperLogDao.insert(sysOperLog);
        return sysOperLog;
    }

    /**
     * 修改数据
     *
     * @param sysOperLog 实例对象
     * @return 实例对象
     */
    @Override
    public SysOperLog update(SysOperLog sysOperLog) {
        this.sysOperLogDao.update(sysOperLog);
        return this.queryById(sysOperLog.getOperId());
    }

    /**
     * 通过主键删除数据
     *
     * @param operId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long operId) {
        return this.sysOperLogDao.deleteById(operId) > 0;
    }
}
